package cn.cloudreal.cbms.resmonitor.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import cn.cloudreal.cbms.common.util.Arith;
import cn.cloudreal.cbms.common.util.Constants;
import cn.cloudreal.cbms.common.util.DatadicContext;
import cn.cloudreal.cbms.common.util.PageBean;
import cn.cloudreal.cbms.common.util.StringUtils;
import cn.cloudreal.cbms.log.service.OptLogService;
import cn.cloudreal.cbms.resmonitor.service.ResMonitorService;
import cn.cloudreal.cbms.vo.Dictionary;
import cn.cloudreal.cbms.vo.FundBudget;
import cn.cloudreal.cbms.vo.Log;
import cn.cloudreal.cbms.vo.Mediasumm;
import cn.cloudreal.cbms.vo.PutInPlanMonth;
import cn.cloudreal.cbms.vo.ResourceMonitor;
import cn.cloudreal.cbms.vo.SourcePlanYear;
import cn.cloudreal.cbms.vo.UserInfo;

import com.opensymphony.xwork2.ActionSupport;

/**
 * <p>
 * Title: ITC
 * </p>
 * <p>
 * Description:资源监控action类
 * </p>
 * <p>
 * Copyright: Copyright (c) 2010
 * </p>
 * <p>
 * Company:云恒瑞通
 * </p>
 * 
 * @author 夏加冬
 * @date 2012-7-9
 */
public class ResMonitorAction extends ActionSupport
{
    /** serialVersionUID */
    private static final long serialVersionUID = 1L;

    /** 日志工具类实例 */
    private static final Logger log = Logger.getLogger(ResMonitorAction.class);

    /** 日志的service */
    private OptLogService optLogService = null;

    /** 资源监控服务 */
    ResMonitorService resMonitorService;

    /** 媒体list */
    List<Mediasumm> mediaSummaries = null;

    /** 媒体 */
    Mediasumm mediaSummary;

    /** 当前页 */
    int currentPage;

    /** 分页对象 */
    PageBean page;

    /** 年份 */
    int year;
    
    String nowDate;       //获取当期的日期

    /** 资源监控 */
    List<ResourceMonitor> resourceMonitors = null;

    /** 年度资源投放计划 */
    SourcePlanYear sourcePlanYear;

    /** 费用预算表 */
    FundBudget fundBudget;

    /** 分阶段投放计划（月度） */
    private List<PutInPlanMonth> putInPlanMonths;

    /** 媒体编号 */
    String mediaName;

    /** 费用类型select */
    List<Dictionary> costTypeList = new ArrayList<Dictionary>();

    /** 费用子类select */
    List<Dictionary> costSubtypeList = new ArrayList<Dictionary>();

    /** 全省 */
    List<Dictionary> allProvinceList;

    /** 进度 */
    List<Dictionary> PrefectureList;

    /** 地市 */
    String city;

    /** 费用类型key */
    String costType;

    /** 费用子类 */
    String costSubType;

    /** 媒体价格id */
    Integer idPrice;

    /** 费用子类备份 */
    String costSubTy;

    /** 关键字 */
    String keyword;

    /** 截止时间 */
    String time;

    /** 进度 */
    Integer plan;

    /** 资源投放计划 */

    Integer sourceId;

    /** 消息 */
    String message;
    /**
     * 列表显示详情日志
     */
    private List<Log> logList;

    /**
     * 资源监控列表
     * 
     * @return String
     */
    @SuppressWarnings("unchecked")
    public String list()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction list() method,return String");
        }
        try
        {
            // 地市
            allProvinceList = DatadicContext.getInstance()
                    .getDicDataListByCode("CITY");
            // 进度
            PrefectureList = DatadicContext.getInstance()
                    .getDicDataListByCode("JD");
            // 关键字
            if (StringUtils.isEmpty(keyword))
            {
                keyword = "";
            }
            // 进度
            if (StringUtils.isEmpty(String.valueOf(plan)))
            {
                plan = 0;
            }
            // 地市
            if ("0".equals(city) || city == null)
            {
                city = "00";
            }
            if (StringUtils.isEmpty(time))
            {
                time = StringUtils.formatDateToString(new Date(), "yyyy-MM");
            }
            // 获取当前session对象中所属城市
            UserInfo userInfo = (UserInfo) ServletActionContext.getRequest()
                    .getSession()
                    .getAttribute(Constants.SESSIONPRKEY);
            // 非空
            if (null != userInfo && city == "00")
            {
                //
                if (userInfo.getUserRole() != null)
                {
                    // 默认东莞
                    city = "DG";
                    // 非空重置
                    if (userInfo.getUsercity() != null)
                    {
                        if (!"".equals(userInfo.getUsercity()))
                        {
                            city = userInfo.getUsercity();
                        }
                    }
                    // 操作范围
                    String roleRange = userInfo.getUserRole().getRoleRange();
                    if (roleRange != null)
                    {

                        // 地市级和 个人
                        if ("2".endsWith(roleRange) || "3".endsWith(roleRange))
                        {
                            allProvinceList.clear();
                            Dictionary dictionary = (Dictionary) DatadicContext.getInstance()
                                    .getDatadicObject(city, "CITY");
                            allProvinceList.add(dictionary);

                        }
                    }
                }
            }

            // 实例化 page分页对象
            page = new PageBean(currentPage == 0 ? 1 : currentPage,
                    Constants.PAGE_SIZE);
            Map condition = new HashMap();
            condition.put("i_endmonth", time + "-01");// 时间段
            condition.put("i_city", city);// 地市
            condition.put("i_searchkey", keyword.trim());// 搜索关键字
            condition.put("i_plan", plan);// 进度
            condition.put("i_selecttype", 1);// 1为总条数，2为结果集
            condition.put("i_starid", 1);// 开始
            condition.put("i_endid", 1);// 结束
            // 查找资源监控列表
            resourceMonitors = resMonitorService.getMediaSummaries(page,
                    condition);

        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction list() method,return String", e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction list() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 跳转到媒体计划投放量录入第一步操作页面
     * 
     * @return String
     */
    public String mediaPlanCountAdd()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanCountAdd() method,return String");
        }
        try
        {
            // 初始化相关参数和下拉框
            Calendar ca = Calendar.getInstance();
            year = ca.get(Calendar.YEAR);
            
            nowDate = StringUtils.formatDateToString(new Date(), "yyyy-MM-dd");
            // 地市
            allProvinceList = DatadicContext.getInstance()
                    .getDicDataListByCode( "CITY");
            // 费用类型
            costTypeList = DatadicContext.getInstance()
                    .getDicDataListByCode("FYLX");
            // 获取当前session对象中所属城市
            UserInfo userInfo = (UserInfo) ServletActionContext.getRequest()
                    .getSession()
                    .getAttribute(Constants.SESSIONPRKEY);
            // 非空
            if (null != userInfo)
            {
                //
                if (userInfo.getUserRole() != null)
                {
                    // 默认东莞
                    city = "DG";
                    // 非空重置
                    if (userInfo.getUsercity() != null)
                    {
                        if (!"".equals(userInfo.getUsercity()))
                        {
                            city = userInfo.getUsercity();
                        }
                    }
                    if (sourcePlanYear == null)
                    {
                        sourcePlanYear = new SourcePlanYear();
                        sourcePlanYear.setCity(city);
                    }
                    // 操作范围
                    String roleRange = userInfo.getUserRole().getRoleRange();
                    if (roleRange != null)
                    {

                        // 地市级和 个人
                        if ("2".endsWith(roleRange) || "3".endsWith(roleRange)
                                || "1".endsWith(roleRange))
                        {
                            allProvinceList.clear();
                            Dictionary dictionary = (Dictionary) DatadicContext.getInstance()
                                    .getDatadicObject(city, "CITY");
                            allProvinceList.add(dictionary);

                        }
                    }
                }
            }

        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanCountAdd() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanCountAdd() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 查找媒体名称
     * 
     * @return String
     */
    public String findMedia()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction findMedia() method,return String");
        }
        try
        {
//            if(null!=mediaName)
//            {
//                mediaName = new String(mediaName.getBytes("ISO-8859-1"), "utf-8");
//            }
            // 根据合同年份和媒体名称查找当前所有的媒体list
            mediaSummaries = resMonitorService.getMediaSummariesByYear(year,
                    mediaName,
                    city);

        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction findMedia() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction findMedia() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 跳转到媒体计划投放量录入第二个操作页面
     * 
     * @return String
     */
    public String mediaPlanCountAddSecond()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanCountAddSecond() method,return String");
        }
        try
        {
            // 设置赠送资源
            sourcePlanYear.setSumPromotionAmount(Arith.add(sourcePlanYear.getPromotionAmount(),
                    Arith.add(sourcePlanYear.getReturnSourceAmount(),
                            sourcePlanYear.getIncrePromotionAmount())));

        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanCountAddSecond() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanCountAddSecond() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 媒体计划投放量录入保存
     * 
     * @return String
     */
    public String mediaPlanCountSave()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanCountSave() method,return String");
        }
        try
        {
            Integer id = resMonitorService.addResMonitorRelatoin(putInPlanMonths,
                    sourcePlanYear,
                    2);
            // 详情日志
            this.findLogMessage("预算",
                    "录入",
                    "T_CB_SOURCEPLANYEAR",
                    String.valueOf(id));

            this.alertMessage("预算录入保存成功", "budgetList.action");
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanCountSave() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanCountSave() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 媒体计划投放量费用计划表录入保存
     * 
     * @return String
     */
    public String mediaPlanBudgetAdd()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanBudgetAdd() method,return String");
        }
        try
        {
            resMonitorService.addResMonitorRelatoin(putInPlanMonths,
                    sourcePlanYear,
                    1);
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanBudgetAdd() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanBudgetAdd() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 获取费用子类
     * 
     * @return
     */
    public String getCostSubtype()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction getCostSubtype() method,return String");
        }
        try
        {
            // 费用子类
            costSubtypeList = DatadicContext.getInstance()
                    .getSubDatadicByCode(costType, "FYLX");
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction getCostSubtype() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction getCostSubtype() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 查看
     * 
     * @return
     */
    public String viewResPut()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction getCostSubtype() method,return String");
        }
        try
        {
            // 获取年度资源投放计划
            sourcePlanYear = resMonitorService.getSourcePlanYear(sourceId);
            // 设置赠送资源
            sourcePlanYear.setSumPromotionAmount(sourcePlanYear.getPromotionAmount()
                    + sourcePlanYear.getReturnSourceAmount()
                    + sourcePlanYear.getIncrePromotionAmount());
            // 地市
            allProvinceList = DatadicContext.getInstance()
                    .getDicDataListByCode("CITY");
            for (int i = 0; i < allProvinceList.size(); i++)
            {
                if (allProvinceList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCity()))
                {
                    sourcePlanYear.setCity(allProvinceList.get(i)
                            .getDatavalue());
                    break;
                }
            }
            // 费用类型
            costTypeList = DatadicContext.getInstance()
                    .getDicDataListByCode("FYLX");
            String costId = null;
            String costSubId = null;
            for (int i = 0; i < costTypeList.size(); i++)
            {
                if (costTypeList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCostType()))
                {
                    costId = sourcePlanYear.getCostType();
                    sourcePlanYear.setCostType(costTypeList.get(i)
                            .getDatavalue());
                    break;
                }
            }
            // 费用子类
            costSubtypeList = DatadicContext.getInstance()
                    .getSubDatadicByCode(costId, "FYLX");
            for (int i = 0; i < costSubtypeList.size(); i++)
            {
                if (costSubtypeList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCostSubtype()))
                {
                    costSubId = sourcePlanYear.getCostSubtype();
                    sourcePlanYear.setCostSubtype(costSubtypeList.get(i)
                            .getDatavalue());
                    break;
                }
            }
            // 分阶段投放计划
            putInPlanMonths = resMonitorService.getPutInPlanMonths(sourcePlanYear.getId_price()
                    .toString(),
                    costId,
                    costSubId);

            Log sample = new Log();
            sample.setRelationId(sourcePlanYear.getId().toString());
            sample.setLogType("T_CB_SOURCEPLANYEAR");
            logList = new ArrayList<Log>();
            logList = optLogService.getLogsBySample(sample);
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction getCostSubtype() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction getCostSubtype() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 跳转到媒体计划投放量更新第一步操作页面
     * 
     * @return String
     */
    public String updateResPut()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction updateResPut() method,return String");
        }
        try
        {
            // 获取年度资源投放计划
            sourcePlanYear = resMonitorService.getSourcePlanYear(sourceId);
            // 设置赠送资源
            sourcePlanYear.setSumPromotionAmount(Arith.add(sourcePlanYear.getPromotionAmount(),
                    Arith.add(sourcePlanYear.getReturnSourceAmount(),
                            sourcePlanYear.getIncrePromotionAmount())));
            nowDate = StringUtils.formatDateToString(new Date(), "yyyy-MM-dd");
            // 地市
            allProvinceList = DatadicContext.getInstance()
                    .getDicDataListByCode("CITY");
            for (int i = 0; i < allProvinceList.size(); i++)
            {
                if (allProvinceList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCity()))
                {
                    sourcePlanYear.setCity(allProvinceList.get(i)
                            .getDatavalue());
                    break;
                }
            }
            // 费用类型
            costTypeList = DatadicContext.getInstance()
                    .getDicDataListByCode("FYLX");
            String costId = null;
            @SuppressWarnings("unused")
            String costSubId = null;
            for (int i = 0; i < costTypeList.size(); i++)
            {
                if (costTypeList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCostType()))
                {
                    costId = sourcePlanYear.getCostType();
                    sourcePlanYear.setCostType(costTypeList.get(i)
                            .getDatavalue());
                    break;
                }
            }
            // 费用子类
            costSubtypeList = DatadicContext.getInstance()
                    .getSubDatadicByCode(costId, "FYLX");
            for (int i = 0; i < costSubtypeList.size(); i++)
            {
                if (costSubtypeList.get(i)
                        .getId()
                        .equals(sourcePlanYear.getCostSubtype()))
                {
                    costSubId = sourcePlanYear.getCostSubtype();
                    sourcePlanYear.setCostSubtype(costSubtypeList.get(i)
                            .getDatavalue());
                    break;
                }
            }
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction updateResPut() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction updateResPut() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 跳转到媒体计划投放量更新第二个操作页面
     * 
     * @return String
     */
    public String mediaPlanCountUpdateSecond()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanCountUpdateSecond() method,return String");
        }
        try
        {
            // 设置赠送资源
            sourcePlanYear.setSumPromotionAmount(Arith.add(sourcePlanYear.getPromotionAmount(),
                    Arith.add(sourcePlanYear.getReturnSourceAmount(),
                            sourcePlanYear.getIncrePromotionAmount())));
            // 费用类型
            costTypeList = DatadicContext.getInstance()
                    .getDicDataListByCode("FYLX");
            for (int i = 0; i < costTypeList.size(); i++)
            {
                if (costTypeList.get(i)
                        .getDatavalue()
                        .equals(sourcePlanYear.getCostType()))
                {
                    sourcePlanYear.setCostType(costTypeList.get(i).getId());
                    break;
                }
            }
            // 费用子类
            costSubtypeList = DatadicContext.getInstance()
                    .getSubDatadicByCode(sourcePlanYear.getCostType(), "FYLX");
            for (int i = 0; i < costSubtypeList.size(); i++)
            {
                if (costSubtypeList.get(i)
                        .getDatavalue()
                        .equals(sourcePlanYear.getCostSubtype()))
                {
                    sourcePlanYear.setCostSubtype(costSubtypeList.get(i)
                            .getId());
                    break;
                }
            }
            // 分阶段投放计划
            putInPlanMonths = resMonitorService.getPutInPlanMonths(sourcePlanYear.getId_price()
                    .toString(),
                    sourcePlanYear.getCostType(),
                    sourcePlanYear.getCostSubtype());

        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanCountUpdateSecond() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanCountUpdateSecond() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 媒体计划投放量更新保存
     * 
     * @return String
     */
    public String mediaPlanCountUpdate()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction mediaPlanCountUpdate() method,return String");
        }
        try
        {
            nowDate = StringUtils.formatDateToString(new Date(), "yyyy-MM-dd");
            PutInPlanMonth ppm = new PutInPlanMonth();
            ppm.setSourceId(sourcePlanYear.getId());
            List<PutInPlanMonth> ppmList = resMonitorService.findPutMonthByNowTotalPutInAndType(ppm);
            if(ppmList!=null && ppmList.size()!=0){
                resMonitorService.updateResMonitorRelatoin(putInPlanMonths,
                        sourcePlanYear);//修改月
            }else{
                resMonitorService.addResMonitorRelatoin_01(putInPlanMonths,
                        sourcePlanYear,
                        2);//修改年
            }
            // 详情日志
            this.findLogMessage("预算",
                    "更新",
                    "T_CB_SOURCEPLANYEAR",
                    String.valueOf(sourcePlanYear.getId()));

            this.alertMessage("媒体计划投放量修改成功", "budgetList.action");
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction mediaPlanCountUpdate() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction mediaPlanCountUpdate() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 录入时判断是否已经存在此资源
     * 
     * @return String
     */
    public String checkSourcePlan()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction checkSourcePlan() method,return String");
        }
        try
        {
            if (idPrice != null)
            {
                // 分阶段投放计划
                sourcePlanYear = resMonitorService.getSourceIsExist(idPrice.toString(),
                        costType,
                        costSubType);
                if (null != sourcePlanYear)
                {
                    message = "error";
                }
                else
                {
                    message = "success";
                }
            }
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction checkSourcePlan() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction checkSourcePlan() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 录入时判断是否已经存在此费用预算
     * 
     * @return String
     */
    public String checkFundBudget()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction checkFundBudget() method,return String");
        }
        try
        {
            // 分阶段投放计划
            fundBudget = resMonitorService.getFundBudgetIsExist(String.valueOf(year),
                    city,
                    costType,
                    costSubType);
            if (null != fundBudget)
            {
                message = "error";
            }
            else
            {
                message = "success";
            }
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction checkFundBudget() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction checkFundBudget() method,return String");
        }
        return SUCCESS;
    }

    /**
     * 选择费用子类的时候显示对应的实体
     * 
     * @return String
     */
    public String selectentity()
    {
        // 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter ResMonitorAction selectentity() method,return String");
        }
        try
        {
            // 费用子类
            costSubtypeList = DatadicContext.getInstance()
                    .getSubDatadicByCode(costType, "FYLX");
            for (int i = 0; i < costSubtypeList.size(); i++)
            {
                if (costSubtypeList.get(i).getId().equals(costSubType))
                {
                    message = costSubtypeList.get(i).getExtAttr1();
                    break;
                }
            }
        }
        catch (Exception e)
        {
            // TODO: handle exception 添加异常信息 返回error
            log.error("Error ResMonitorAction selectentity() method,return String",
                    e);
            return ERROR;
        }

        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit ResMonitorAction selectentity() method,return String");
        }
        return SUCCESS;
    }

    // 获取日志
    public void findLogMessage(String addOrUpdateMsg,
            String typeName,
            String tableName,
            String tableID)
    {
        // 日志记录
        UserInfo userSession = (UserInfo) ServletActionContext.getRequest()
                .getSession()
                .getAttribute("logUser");
        String user = null;
        String cityCode = null;
        String cityName = null;
        String organizaOragName = null;
        if (null == userSession)
        {
            user = "张三";
            cityName = "东莞";
            organizaOragName = "市场部";
            cityCode = "DG";
        }
        else
        {
            user = userSession.getUserName();
            cityCode = userSession.getUsercity();
            cityName = userSession.getCityName();
            organizaOragName = userSession.getOrganiza().getOrgName();
        }
        if (null == cityCode)
        {
            cityCode = "";
            cityName = "东莞";
        }
        Timestamp d = new Timestamp(System.currentTimeMillis());
        String content = d + " " + cityName + organizaOragName + user
                + addOrUpdateMsg + typeName;
        String datatime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
        // System.out.println("data======"+data);
        /** 获取变更记录的数据 */
        Log logRecord = new Log(tableName,
                content,
                tableID,
                datatime,
                user,
                cityCode,
                organizaOragName,
                "");
        optLogService.addLog(logRecord);
    }

    /**
     * 弹出提示信息
     */
    private void alertMessage(String message, String url)
    {
        try
        {
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html; charset=utf-8");
            PrintWriter out = response.getWriter();
            out = response.getWriter();
            out.println(" <script type='text/javascript' >");
            out.println("alert('" + message + "');");
            out.println("location='" + url + "'");
            out.println(" </script>");
            out.flush();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
    
    /**
     * 返回当前年月日
     * 
     * @return
     */
    private String getYearMonth()
    {
        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        return df.format(c.getTime());
    }

    public ResMonitorService getResMonitorService()
    {
        return resMonitorService;
    }

    public void setResMonitorService(ResMonitorService resMonitorService)
    {
        this.resMonitorService = resMonitorService;
    }

    public List<Mediasumm> getMediaSummaries()
    {
        return mediaSummaries;
    }

    public void setMediaSummaries(List<Mediasumm> mediaSummaries)
    {
        this.mediaSummaries = mediaSummaries;
    }

    public Mediasumm getMediaSummary()
    {
        return mediaSummary;
    }

    public void setMediaSummary(Mediasumm mediaSummary)
    {
        this.mediaSummary = mediaSummary;
    }

    public int getCurrentPage()
    {
        return currentPage;
    }

    public void setCurrentPage(int currentPage)
    {
        this.currentPage = currentPage;
    }

    public PageBean getPage()
    {
        return page;
    }

    public void setPage(PageBean page)
    {
        this.page = page;
    }

    public static long getSerialversionuid()
    {
        return serialVersionUID;
    }

    public static Logger getLog()
    {
        return log;
    }

    public int getYear()
    {
        return year;
    }

    public void setYear(int year)
    {
        this.year = year;
    }

    public SourcePlanYear getSourcePlanYear()
    {
        return sourcePlanYear;
    }

    public void setSourcePlanYear(SourcePlanYear sourcePlanYear)
    {
        this.sourcePlanYear = sourcePlanYear;
    }

    public List<PutInPlanMonth> getPutInPlanMonths()
    {
        return putInPlanMonths;
    }

    public void setPutInPlanMonths(List<PutInPlanMonth> putInPlanMonths)
    {
        this.putInPlanMonths = putInPlanMonths;
    }

    public String getMediaName()
    {
        return mediaName;
    }

    public void setMediaName(String mediaName)
    {
        this.mediaName = mediaName;
    }

    public List<Dictionary> getCostTypeList()
    {
        return costTypeList;
    }

    public void setCostTypeList(List<Dictionary> costTypeList)
    {
        this.costTypeList = costTypeList;
    }

    public List<Dictionary> getCostSubtypeList()
    {
        return costSubtypeList;
    }

    public void setCostSubtypeList(List<Dictionary> costSubtypeList)
    {
        this.costSubtypeList = costSubtypeList;
    }

    public List<Dictionary> getAllProvinceList()
    {
        return allProvinceList;
    }

    public void setAllProvinceList(List<Dictionary> allProvinceList)
    {
        this.allProvinceList = allProvinceList;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCostType()
    {
        return costType;
    }

    public void setCostType(String costType)
    {
        this.costType = costType;
    }

    public List<ResourceMonitor> getResourceMonitors()
    {
        return resourceMonitors;
    }

    public void setResourceMonitors(List<ResourceMonitor> resourceMonitors)
    {
        this.resourceMonitors = resourceMonitors;
    }

    public String getKeyword()
    {
        return keyword;
    }

    public void setKeyword(String keyword)
    {
        this.keyword = keyword;
    }

    public String getTime()
    {
        return time;
    }

    public void setTime(String time)
    {
        this.time = time;
    }

    public Integer getPlan()
    {
        return plan;
    }

    public void setPlan(Integer plan)
    {
        this.plan = plan;
    }

    public List<Dictionary> getPrefectureList()
    {
        return PrefectureList;
    }

    public void setPrefectureList(List<Dictionary> prefectureList)
    {
        PrefectureList = prefectureList;
    }

    public String getCostSubType()
    {
        return costSubType;
    }

    public void setCostSubType(String costSubType)
    {
        this.costSubType = costSubType;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public String getCostSubTy()
    {
        return costSubTy;
    }

    public void setCostSubTy(String costSubTy)
    {
        this.costSubTy = costSubTy;
    }

    public Integer getSourceId()
    {
        return sourceId;
    }

    public void setSourceId(Integer sourceId)
    {
        this.sourceId = sourceId;
    }

    public Integer getIdPrice()
    {
        return idPrice;
    }

    public void setIdPrice(Integer idPrice)
    {
        this.idPrice = idPrice;
    }

    public OptLogService getOptLogService()
    {
        return optLogService;
    }

    public void setOptLogService(OptLogService optLogService)
    {
        this.optLogService = optLogService;
    }

    public List<Log> getLogList()
    {
        return logList;
    }

    public void setLogList(List<Log> logList)
    {
        this.logList = logList;
    }

    public String getNowDate()
    {
        return nowDate;
    }

    public void setNowDate(String nowDate)
    {
        this.nowDate = nowDate;
    }

}
